﻿

Namespace DoFactory.GangOfFour.Template.Structural


    ''' <summary>
    ''' MainApp startup class for Real-World 
    ''' Template Design Pattern.
    ''' </summary>
    Public Class MainApp


        ''' <summary>
        ''' Entry point into console application.
        ''' </summary>
        Public Shared Sub Main()

            Dim aA As AbstractClass = New ConcreteClassA()

            aA.TemplateMethod()

            Dim aB As AbstractClass = New ConcreteClassB()

            aB.TemplateMethod()

            ' Wait for user
            'Console.ReadKey()

        End Sub

    End Class



    ''' <summary>
    ''' The 'AbstractClass' abstract class
    ''' </summary>
    MustInherit Class AbstractClass

        Public MustOverride Sub PrimitiveOperation1()

        Public MustOverride Sub PrimitiveOperation2()

        ' The "Template method"
        Public Sub TemplateMethod()

            PrimitiveOperation1()

            PrimitiveOperation2()

            Console.WriteLine("")

        End Sub

    End Class



    ''' <summary>
    ''' A 'ConcreteClass' class
    ''' </summary>
    Class ConcreteClassA
        Inherits AbstractClass


        Public Overrides Sub PrimitiveOperation1()
            Console.WriteLine("ConcreteClassA.PrimitiveOperation1()")
        End Sub

        Public Overrides Sub PrimitiveOperation2()
            Console.WriteLine("ConcreteClassA.PrimitiveOperation2()")
        End Sub

    End Class



    ''' <summary>
    ''' A 'ConcreteClass' class
    ''' </summary>
    Class ConcreteClassB
        Inherits AbstractClass


        Public Overrides Sub PrimitiveOperation1()
            Console.WriteLine("ConcreteClassB.PrimitiveOperation1()")
        End Sub

        Public Overrides Sub PrimitiveOperation2()
            Console.WriteLine("ConcreteClassB.PrimitiveOperation2()")
        End Sub

    End Class

End Namespace
